﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataService;
using DTO;

public partial class AccountInfomation_Users_Default : BasePage
{
    private UserService _userService;
    private CustomerService _customerService;
    private IList<User> _users;
    public AccountInfomation_Users_Default()
    {
        _userService = new UserService();
        _customerService = new CustomerService();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        _users = _userService.GetListUserByAccountId(UserLogin.Customer.Id);
        dlUsers.DataSource = _users;
        dlUsers.DataBind();
    }
    protected void dlUsers_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            if (_users[e.Item.ItemIndex].IsAdmin)
            {
                LinkButton lbtDelete = (LinkButton)e.Item.FindControl("lbtDelete");
                lbtDelete.Visible = false;
            }
        }
    }
    protected void dlUsers_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "EditUser")
        {
            Session["EditUser"] = _users[e.Item.ItemIndex];
            Response.Redirect("editUser.aspx?u="+_users[e.Item.ItemIndex].Username);
        }
        else if (e.CommandName == "DeleteUser")
        {
            _userService.DeleteUserByUserId(_users[e.Item.ItemIndex].Id);
            Response.Redirect("Default.aspx");
        }

    }
}